package com.bj.dz.service.impl;

import com.bj.dz.entity.TrafficBridgeData;
import com.bj.dz.mapper.TrafficBridgeDataMapper;
import com.bj.dz.service.TrafficBridgeDataService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class TrafficBridgeDataServiceImpl implements TrafficBridgeDataService {

    @Resource
    private TrafficBridgeDataMapper trafficBridgeDataMapper;

    public TrafficBridgeData getTrafficBridgeDataById(Integer id){
        return trafficBridgeDataMapper.getTrafficBridgeDataById(id);
    }

    public List<TrafficBridgeData>	getTrafficBridgeDataListByMap(Map<String,Object> param){
        return trafficBridgeDataMapper.getTrafficBridgeDataListByMap(param);
    }

    public Integer getTrafficBridgeDataCountByMap(Map<String,Object> param){
        return trafficBridgeDataMapper.getTrafficBridgeDataCountByMap(param);
    }

    @Transactional
    public boolean addTrafficBridgeData(TrafficBridgeData trafficBridgeData){
            return trafficBridgeDataMapper.insertTrafficBridgeData(trafficBridgeData)>0?true:false;
    }

    @Transactional
    public boolean modifyTrafficBridgeData(TrafficBridgeData trafficBridgeData){
        return trafficBridgeDataMapper.updateTrafficBridgeData(trafficBridgeData)>0?true:false;
    }

    @Transactional
    public boolean deleteTrafficBridgeDataById(Integer id){
        return trafficBridgeDataMapper.deleteTrafficBridgeDataById(id)>0?true:false;
    }

    public Page<TrafficBridgeData> queryTrafficBridgeDataPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = trafficBridgeDataMapper.getTrafficBridgeDataCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<TrafficBridgeData> trafficBridgeDataList = trafficBridgeDataMapper.getTrafficBridgeDataListByMap(param);
        page.setRows(trafficBridgeDataList);
        return page;
    }

}
